package com.vf.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.vf.common.annotation.Anonymous;
import com.vf.user.domain.DTO.GroupTypeDTO;
import com.vf.user.domain.DTO.JoinGroupTypeDTO;
import com.vf.user.domain.VO.GroupTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vf.common.annotation.Log;
import com.vf.common.core.controller.BaseController;
import com.vf.common.core.domain.AjaxResult;
import com.vf.common.enums.BusinessType;
import com.vf.user.domain.GroupType;
import com.vf.user.service.IGroupTypeService;
import com.vf.common.utils.poi.ExcelUtil;
import com.vf.common.core.page.TableDataInfo;

/**
 * 分组类型Controller
 * 
 * @author LBS
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/user/groupType")
@Api(tags = "分组类型")
public class GroupTypeController extends BaseController
{
    @Autowired
    private IGroupTypeService groupTypeService;

    /**
     * 查询分组类型列表
     */
    @PreAuthorize("@ss.hasPermi('user:groupType:list')")
    @GetMapping("/list")
    public TableDataInfo list(GroupType groupType)
    {
        startPage();
        List<GroupType> list = groupTypeService.selectGroupTypeList(groupType);
        return getDataTable(list);
    }

    /**
     * 导出分组类型列表
     */
    @PreAuthorize("@ss.hasPermi('user:groupType:export')")
    @Log(title = "分组类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GroupType groupType)
    {
        List<GroupType> list = groupTypeService.selectGroupTypeList(groupType);
        ExcelUtil<GroupType> util = new ExcelUtil<GroupType>(GroupType.class);
        util.exportExcel(response, list, "分组类型数据");
    }

    /**
     * 获取分组类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:groupType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(groupTypeService.selectGroupTypeById(id));
    }

    /**
     * 新增分组类型
     */
    @PreAuthorize("@ss.hasPermi('user:groupType:add')")
    @Log(title = "分组类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupType groupType)
    {
        return toAjax(groupTypeService.insertGroupType(groupType));
    }

    /**
     * 修改分组类型
     */
    @PreAuthorize("@ss.hasPermi('user:groupType:edit')")
    @Log(title = "分组类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupType groupType)
    {
        return toAjax(groupTypeService.updateGroupType(groupType));
    }

    /**
     * 删除分组类型
     */
    @PreAuthorize("@ss.hasPermi('user:groupType:remove')")
    @Log(title = "分组类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(groupTypeService.deleteGroupTypeByIds(ids));
    }

    /**
     * 查询用户分组类型列表
     */
    @Anonymous
    @ApiOperation( value = "查询用户分组类型列表")
    @GetMapping("/groupList")
    public TableDataInfo groupList()
    {
        List<GroupTypeDTO> list = groupTypeService.selectGroupList();
        return getDataTable(list);
    }


    @Anonymous
    @ApiOperation( value = "通过Id查询分组用户")
    @GetMapping("/getGroupDetail")
    public TableDataInfo getGroupDetail(Long id)
    {
        List<GroupTypeVO> list = groupTypeService.getGroupDetail(id);
        return getDataTable(list);
    }

    @Anonymous
    @ApiOperation( value = "加入这个分组")
    @PostMapping("/joinGroup")
    public AjaxResult joinGroup(@RequestBody JoinGroupTypeDTO joinGroupTypeDTO){
        return success( groupTypeService.joinGroup(joinGroupTypeDTO)) ;

    }
}
